/*****************************************************************************
*        描述 :
*             文件描述
*        CLR版本:            3.5
*        创建者 :            蒋 光
*        个人域名:           jiangguang.net.cn
*        命名空间名称:       ECP.DataAccess
*        文件名:             BaseDao.cs
*        创建系统时间:       2012/11/2 19:06:59
*        创建年份:           2012
*
/*****************************************************************************/

namespace ECP.DataAccess
{
    using System;
    using System.Data;
    using ECP.DataAccess.Utilities;
    using ECP.Utilities;

    public abstract class BaseDao : IBaseDao
    {
        public bool AllowDelete;
        public bool AllowEdit;
        public string CategoryID;
        public string Code;
        public string CreateDate;
        public string CreateUserID;
        public string CurrentTableName;

        [NonSerialized]
        protected IDbHelper DbHelper;

        public string Description;
        public bool Enabled;
        public string FullName;
        public bool GetBySetProperty;
        public string ID;
        public string ModifyDate;
        public string ModifyUserID;
        public string NextID;
        public string OrganizeID;
        public string ParentID;
        public string PreviousID;
        private string returnStatusCode;
        private string returnStatusMessage;
        public string SortCode;
        public string StateCode;
        public int TopLimit;

        [NonSerialized]
        protected BaseUserInfo UserInfo;

        public bool UseStoredProcedure;
        public string VersionNumber;
        public bool WorkFlow;

        public BaseDao()
        {
            this.ID = string.Empty;
            this.ParentID = string.Empty;
            this.OrganizeID = string.Empty;
            this.CategoryID = string.Empty;
            this.Code = string.Empty;
            this.FullName = string.Empty;
            this.AllowEdit = true;
            this.AllowDelete = true;
            this.StateCode = "0";
            this.Description = string.Empty;
            this.SortCode = string.Empty;
            this.CreateUserID = string.Empty;
            this.CreateDate = string.Empty;
            this.ModifyUserID = string.Empty;
            this.ModifyDate = string.Empty;
            this.CurrentTableName = string.Empty;
            this.VersionNumber = "001.001.001.001";
            this.GetBySetProperty = true;
            this.TopLimit = 100;
            this.returnStatusCode = StatusCode.OK.ToString();
            this.returnStatusMessage = string.Empty;
            this.PreviousID = string.Empty;
            this.NextID = string.Empty;
        }

        public BaseDao(IDbHelper dbHelper)
            : this()
        {
            this.DbHelper = dbHelper;
        }

        public BaseDao(IDbHelper dbHelper, BaseUserInfo userInfo)
            : this(dbHelper)
        {
            this.UserInfo = userInfo;
        }

        public virtual bool AddAfter()
        {
            return true;
        }

        public virtual bool AddBefore()
        {
            return true;
        }

        public virtual string AddEntity(object entity)
        {
            return string.Empty;
        }

        public virtual int BatchDelete(string[] ids)
        {
            return DbLogic.BatchDelete(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, ids);
        }

        public virtual int BatchDelete(string name, object[] values)
        {
            return DbLogic.BatchDelete(this.DbHelper, this.CurrentTableName, name, values);
        }

        public virtual int BatchDelete(string[] names, object[] values)
        {
            return DbLogic.BatchDelete(this.DbHelper, this.CurrentTableName, names, values);
        }

        public virtual int BatchDelete(string[] ids, bool force)
        {
            return DbLogic.BatchDelete(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, ids);
        }

        public virtual int BatchDelete(IDbHelper dbHelper, string[] ids)
        {
            this.DbHelper = dbHelper;
            return DbLogic.BatchDelete(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, ids);
        }

        public virtual int BatchDelete(IDbHelper dbHelper, BaseUserInfo userInfo, string[] ids)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.BatchDelete(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, ids);
        }

        public virtual int BatchDelete(string[] names, object[] values, bool force)
        {
            return DbLogic.BatchDelete(this.DbHelper, this.CurrentTableName, names, values);
        }

        public virtual int BatchSave(DataTable dataTable)
        {
            return 0;
        }

        public virtual int BatchSave(IDbHelper dbHelper, BaseUserInfo userInfo, DataTable dataTable)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return this.BatchSave(dataTable);
        }

        public int BatchSetCode(string[] ids, string[] codes)
        {
            int num = 0;
            for (int i = 0; i < ids.Length; i++)
            {
                num += this.SetProperty(ids[i], BaseBusinessLogic.FieldCode, codes[i]);
            }
            return num;
        }

        public int BatchSetSortCode(string[] ids)
        {
            int num = 0;
            string[] strArray = BaseSequenceDao.Instance.GetBatchSequence(this.DbHelper, this.CurrentTableName, ids.Length);
            for (int i = 0; i < ids.Length; i++)
            {
                num += this.SetProperty(ids[i], BaseBusinessLogic.FieldSortCode, strArray[i]);
            }
            return num;
        }

        public virtual int ChangeEnabled(string id)
        {
            string sqlQuery = " UPDATE " + this.CurrentTableName + " SET " + BaseBusinessLogic.FieldEnabled + " = (CASE " + BaseBusinessLogic.FieldEnabled + " WHEN 0 THEN 1 WHEN 1 THEN 0 END)  WHERE (" + BaseBusinessLogic.FieldID + " = " + this.DbHelper.GetParameter(BaseBusinessLogic.FieldID) + ")";
            string[] targetFileds = new string[1];
            object[] targetValues = new object[1];
            targetFileds[0] = BaseBusinessLogic.FieldID;
            targetValues[0] = id;
            return this.DbHelper.ExecuteNonQuery(sqlQuery, this.DbHelper.MakeParameters(targetFileds, targetValues));
        }

        public bool ConvertIntToBoolean(object Object)
        {
            if (Object == DBNull.Value)
            {
                return false;
            }
            return Object.ToString().Equals("1");
        }

        public DateTime ConvertToDateTime(object Object)
        {
            if (Object == DBNull.Value)
            {
                return DateTime.Now;
            }
            return Convert.ToDateTime(Object);
        }

        public decimal ConvertToDecimal(object Object)
        {
            if (Object == DBNull.Value)
            {
                return 0M;
            }
            return Convert.ToDecimal(Object);
        }

        public int ConvertToInt(object Object)
        {
            if (Object == DBNull.Value)
            {
                return 0;
            }
            return Convert.ToInt32(Object);
        }

        public string ConvertToString(object Object)
        {
            if (Object == DBNull.Value)
            {
                return string.Empty;
            }
            return Object.ToString();
        }

        public virtual int Delete()
        {
            return DbLogic.Delete(this.DbHelper, this.CurrentTableName);
        }

        public virtual int Delete(string id)
        {
            return this.DeleteEntity(id);
        }

        public virtual int Delete(IDbHelper dbHelper, string id)
        {
            this.DbHelper = dbHelper;
            return this.Delete(id);
        }

        public virtual int Delete(string id, bool force)
        {
            return DbLogic.Delete(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id);
        }

        public virtual int Delete(string name, object value)
        {
            return DbLogic.Delete(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual int Delete(IDbHelper dbHelper, BaseUserInfo userInfo, string id)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return this.Delete(id);
        }

        public virtual int Delete(IDbHelper dbHelper, string name, object value)
        {
            this.DbHelper = dbHelper;
            return DbLogic.Delete(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual int Delete(string name, object value, bool force)
        {
            return DbLogic.Delete(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual int Delete(IDbHelper dbHelper, BaseUserInfo userInfo, string name, object value)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.Delete(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual int Delete(string name1, object value1, string name2, object value2)
        {
            return DbLogic.Delete(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual int Delete(string name1, object value1, string name2, object value2, bool force)
        {
            return DbLogic.Delete(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual bool DeleteAfter(string id)
        {
            return true;
        }

        public virtual bool DeleteBefore(string id)
        {
            return true;
        }

        public virtual int DeleteEntity(string id)
        {
            return this.DeleteEntity(BaseBusinessLogic.FieldID, id);
        }

        public virtual int DeleteEntity(string name, object value)
        {
            return DbLogic.Delete(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual bool Exists(string[] ids)
        {
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, ids);
        }

        public virtual bool Exists(string id)
        {
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id);
        }

        public virtual bool Exists(IDbHelper dbHelper, string id)
        {
            this.DbHelper = dbHelper;
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id);
        }

        public virtual bool Exists(string[] names, object[] values)
        {
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, names, values);
        }

        public virtual bool Exists(string name, object value)
        {
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual bool Exists(IDbHelper dbHelper, string name, object value)
        {
            this.DbHelper = dbHelper;
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual bool Exists(string name, object value, string id)
        {
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, name, value, id);
        }

        public virtual bool Exists(IDbHelper dbHelper, string name, object value, string id)
        {
            this.DbHelper = dbHelper;
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, name, value, id);
        }

        public virtual bool Exists(string name1, object value1, string name2, object value2)
        {
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual bool Exists(IDbHelper dbHelper, string name1, object value1, string name2, object value2)
        {
            this.DbHelper = dbHelper;
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual bool Exists(string name1, object value1, string name2, object value2, string id)
        {
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2, BaseBusinessLogic.FieldID, id);
        }

        public virtual bool Exists(IDbHelper dbHelper, string name1, object value1, string name2, object value2, string id)
        {
            this.DbHelper = dbHelper;
            return DbLogic.Exists(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2, BaseBusinessLogic.FieldID, id);
        }

        public virtual string FindID(string[] names, object[] values)
        {
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, names, values, BaseBusinessLogic.FieldID);
        }

        public virtual string FindID(string name, object value)
        {
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, name, value, BaseBusinessLogic.FieldID);
        }

        public virtual string FindID(string name1, object value1, string name2, object value2)
        {
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2, BaseBusinessLogic.FieldID);
        }

        public virtual DataTable Get(string id)
        {
            return this.GetDT(BaseBusinessLogic.FieldID, id);
        }

        public virtual DataTable Get(IDbHelper dbHelper, string id)
        {
            this.DbHelper = dbHelper;
            return this.Get(id);
        }

        public virtual object Get(DataTable dataTable, string id)
        {
            return this.GetFrom(dataTable, BaseBusinessLogic.FieldID, id);
        }

        public virtual DataTable Get(string name, object value)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual DataTable Get(IDbHelper dbHelper, BaseUserInfo userInfo, string id)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return this.Get(id);
        }

        public virtual object Get(DataTable dataTable, string name, object value)
        {
            return this.GetFrom(dataTable, name, value);
        }

        public virtual DataTable Get(string name1, object value1, string name2, object value2)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual DataTable Get(IDbHelper dbHelper, string name1, object value1, string name2, object value2)
        {
            this.DbHelper = dbHelper;
            return this.Get(name1, value1, name2, value2);
        }

        public virtual bool GetAfter(string id)
        {
            return true;
        }

        public virtual bool GetBefore(string id)
        {
            return true;
        }

        public DataTable GetChildrens(string fieldID, string id, string fieldParentID, string order)
        {
            return DbLogic.GetChildrens(this.DbHelper, this.CurrentTableName, fieldID, id, fieldParentID, order);
        }

        public DataTable GetChildrensByCode(string fieldCode, string code, string order)
        {
            return DbLogic.GetChildrensByCode(this.DbHelper, this.CurrentTableName, fieldCode, code, order);
        }

        public string[] GetChildrensID(string fieldID, string id, string fieldParentID)
        {
            return DbLogic.GetChildrensID(this.DbHelper, this.CurrentTableName, fieldID, id, fieldParentID, string.Empty);
        }

        public string[] GetChildrensIDByCode(string fieldCode, string code)
        {
            return DbLogic.GetChildrensIDByCode(this.DbHelper, this.CurrentTableName, fieldCode, code, string.Empty);
        }

        public string GetCode(string id)
        {
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id, BaseBusinessLogic.FieldCode);
        }

        public virtual DataTable GetDT()
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName);
        }

        public virtual DataTable GetDT(string[] ids)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, ids);
        }

        public virtual DataTable GetDT(IDbHelper dbHelper)
        {
            this.DbHelper = dbHelper;
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName);
        }

        public virtual DataTable GetDT(string order)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, order);
        }

        public virtual DataTable GetDT(IDbHelper dbHelper, BaseUserInfo userInfo)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName);
        }

        public virtual DataTable GetDT(string[] names, object[] values)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, names, values);
        }

        public virtual DataTable GetDT(string order, int topLimit)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, order, topLimit);
        }

        public virtual DataTable GetDT(string name, object[] values)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name, values);
        }

        public virtual DataTable GetDT(string name, object value)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual DataTable GetDT(string[] names, object[] values, string order)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, names, values, order);
        }

        public virtual DataTable GetDT(string name, object value, string order)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name, value, order);
        }

        public virtual DataTable GetDT(string name, object[] values, string order)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name, values, order);
        }

        public virtual DataTable GetDT(string[] names, object[] values, string order, int topLimit)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, names, values, order, topLimit);
        }

        public virtual DataTable GetDT(string name, object value, string order, int topLimit)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name, value, order, topLimit);
        }

        public virtual DataTable GetDT(string name1, object value1, string name2, object value2)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual DataTable GetDT(string name1, object value1, string name2, object value2, string order)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2, order);
        }

        public virtual DataTable GetDT(string name1, object value1, string name2, object value2, string order, int topLimit)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2, order, topLimit);
        }

        public DataTable GetDTByCategory(string categoryID)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldCategoryID, categoryID, BaseBusinessLogic.FieldSortCode);
        }

        public DataTable GetDTByCategory(IDbHelper dbHelper, string categoryID)
        {
            this.DbHelper = dbHelper;
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldCategoryID, categoryID, BaseBusinessLogic.FieldSortCode);
        }

        public DataTable GetDTByParent(string parentID)
        {
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldParentID, parentID, BaseBusinessLogic.FieldSortCode);
        }

        public DataTable GetDTByParent(IDbHelper dbHelper, string parentID)
        {
            this.DbHelper = dbHelper;
            return DbLogic.GetDT(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldParentID, parentID, BaseBusinessLogic.FieldSortCode);
        }

        public virtual object GetFrom(DataRow dataRow)
        {
            return this;
        }

        public virtual object GetFrom(DataTable dataTable)
        {
            return this.GetFrom(dataTable, string.Empty);
        }

        public virtual object GetFrom(DataTable dataTable, string id)
        {
            return this.GetFrom(dataTable, BaseBusinessLogic.FieldID, id);
        }

        public virtual object GetFrom(DataTable dataTable, string name, object value)
        {
            foreach (DataRow row in dataTable.Rows)
            {
                if (((value == null) || (value.ToString().Length == 0)) || row[name].ToString().Equals(value))
                {
                    this.GetFrom(row);
                    break;
                }
            }
            return this;
        }

        public virtual object GetFromDS(DataSet dataSet)
        {
            return this.GetFromDS(dataSet, this.CurrentTableName, string.Empty);
        }

        public virtual object GetFromDS(DataSet dataSet, string id)
        {
            return this.GetFrom(dataSet.Tables[this.CurrentTableName], BaseBusinessLogic.FieldID, id);
        }

        public virtual object GetFromDS(DataSet dataSet, string name, object value)
        {
            return this.GetFrom(dataSet.Tables[this.CurrentTableName], BaseBusinessLogic.FieldID, value);
        }

        public string GetFullName(string id)
        {
            return this.GetProperty(BaseBusinessLogic.FieldID, id, BaseBusinessLogic.FieldFullName);
        }

        public string GetFullNameByCategory(string categoryID, string code)
        {
            return this.GetProperty(BaseBusinessLogic.FieldCategoryID, categoryID, BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldFullName);
        }

        public string GetFullNameByCode(string code)
        {
            return this.GetProperty(BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldFullName);
        }

        public string GetID(string code)
        {
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldID);
        }

        public virtual string[] GetIDs()
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName);
        }

        public virtual string[] GetIDs(IDbHelper dbHelper)
        {
            this.DbHelper = dbHelper;
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName);
        }

        public virtual string[] GetIDs(string targetField)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, targetField);
        }

        public virtual string[] GetIDs(IDbHelper dbHelper, BaseUserInfo userInfo)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName);
        }

        public virtual string[] GetIDs(string name, object[] values)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, name, values);
        }

        public virtual string[] GetIDs(string targetField, int topLimit)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, targetField, topLimit);
        }

        public virtual string[] GetIDs(string name, object value)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, name, value);
        }

        public virtual string[] GetIDs(string[] names, object[] values)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, names, values);
        }

        public virtual string[] GetIDs(string name, object value, string targetField)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, name, value, targetField);
        }

        public virtual string[] GetIDs(string[] names, object[] values, string targetField)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, names, values, targetField);
        }

        public virtual string[] GetIDs(string name, object[] values, string targetField)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, name, values, targetField);
        }

        public virtual string[] GetIDs(string[] names, object[] values, string targetField, int topLimit)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, names, values, targetField, topLimit);
        }

        public virtual string[] GetIDs(string name, object value, string targetField, int topLimit)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, name, value, targetField, topLimit);
        }

        public virtual string[] GetIDs(string name1, object value1, string name2, object value2)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2);
        }

        public virtual string[] GetIDs(string name1, object value1, string name2, object value2, string targetField)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2, targetField);
        }

        public virtual string[] GetIDs(string name1, object value1, string name2, object value2, string targetField, int topLimit)
        {
            return DbLogic.GetIDs(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2, targetField, topLimit);
        }

        private string GetNextID(string id)
        {
            string str = string.Empty;
            string str3 = " SELECT TOP 1 " + BaseBusinessLogic.FieldID + " FROM " + this.CurrentTableName + " WHERE " + BaseBusinessLogic.FieldCreateDate + " = (SELECT MIN(" + BaseBusinessLogic.FieldCreateDate + ") FROM " + this.CurrentTableName + " WHERE (" + BaseBusinessLogic.FieldCreateDate + "> (SELECT " + BaseBusinessLogic.FieldCreateDate + " FROM " + this.CurrentTableName + " WHERE " + BaseBusinessLogic.FieldID + " = " + this.DbHelper.GetParameter(BaseBusinessLogic.FieldID) + "))";
            string sqlQuery = str3 + " AND (" + BaseBusinessLogic.FieldCreateUserID + " = " + this.DbHelper.GetParameter(BaseBusinessLogic.FieldCreateUserID) + ") AND ( " + BaseBusinessLogic.FieldDeleteMark + " = 0 )) ";
            string[] targetFileds = new string[2];
            object[] targetValues = new object[2];
            targetFileds[0] = BaseBusinessLogic.FieldID;
            targetValues[0] = id;
            targetFileds[1] = BaseBusinessLogic.FieldCreateUserID;
            targetValues[1] = this.UserInfo.ID;
            object obj2 = this.DbHelper.ExecuteScalar(sqlQuery, this.DbHelper.MakeParameters(targetFileds, targetValues));
            if (obj2 != null)
            {
                str = obj2.ToString();
            }
            return str;
        }

        public string GetNextID(DataTable dataTable, string id)
        {
            string str = string.Empty;
            bool flag = false;
            foreach (DataRowView view in dataTable.DefaultView)
            {
                if (flag)
                {
                    return view[BaseBusinessLogic.FieldID].ToString();
                }
                if (view[BaseBusinessLogic.FieldID].ToString().Equals(id))
                {
                    flag = true;
                }
            }
            return str;
        }

        public DataTable GetParentChildrensByCode(string fieldCode, string code, string order)
        {
            return DbLogic.GetParentChildrensByCode(this.DbHelper, this.CurrentTableName, fieldCode, code, order);
        }

        public string[] GetParentChildrensIDByCode(string fieldCode, string code)
        {
            return DbLogic.GetParentChildrensIDByCode(this.DbHelper, this.CurrentTableName, fieldCode, code, string.Empty);
        }

        public string GetParentID(string id)
        {
            return this.GetProperty(BaseBusinessLogic.FieldID, id, BaseBusinessLogic.FieldParentID);
        }

        public string GetParentIDByCategory(string categoryID, string code)
        {
            return this.GetProperty(BaseBusinessLogic.FieldCategoryID, categoryID, BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldParentID);
        }

        public string GetParentIDByCode(string code)
        {
            return this.GetProperty(BaseBusinessLogic.FieldCode, code, BaseBusinessLogic.FieldParentID);
        }

        public string GetParentIDByCode(string fieldCode, string code)
        {
            return DbLogic.GetParentIDByCode(this.DbHelper, this.CurrentTableName, fieldCode, code);
        }

        public DataTable GetParentsByCode(string fieldCode, string code, string order)
        {
            return DbLogic.GetParentsByCode(this.DbHelper, this.CurrentTableName, fieldCode, code, order);
        }

        public string[] GetParentsIDByCode(string fieldCode, string code)
        {
            return DbLogic.GetParentsIDByCode(this.DbHelper, this.CurrentTableName, fieldCode, code, string.Empty);
        }

        private string GetPreviousID(string id)
        {
            string str = string.Empty;
            string str3 = " SELECT TOP 1 " + BaseBusinessLogic.FieldID + " FROM " + this.CurrentTableName + " WHERE " + BaseBusinessLogic.FieldCreateDate + " = (SELECT MAX(" + BaseBusinessLogic.FieldCreateDate + ") FROM " + this.CurrentTableName + " WHERE (" + BaseBusinessLogic.FieldCreateDate + "< (SELECT " + BaseBusinessLogic.FieldCreateDate + " FROM " + this.CurrentTableName + " WHERE " + BaseBusinessLogic.FieldID + " = " + this.DbHelper.GetParameter(BaseBusinessLogic.FieldID) + "))";
            string sqlQuery = str3 + " AND (" + BaseBusinessLogic.FieldCreateUserID + " = " + this.DbHelper.GetParameter(BaseBusinessLogic.FieldCreateUserID) + " ) AND ( " + BaseBusinessLogic.FieldDeleteMark + " = 0 )) ";
            string[] targetFileds = new string[2];
            object[] targetValues = new object[2];
            targetFileds[0] = BaseBusinessLogic.FieldID;
            targetValues[0] = id;
            targetFileds[1] = BaseBusinessLogic.FieldCreateUserID;
            targetValues[1] = this.UserInfo.ID;
            object obj2 = this.DbHelper.ExecuteScalar(sqlQuery, this.DbHelper.MakeParameters(targetFileds, targetValues));
            if (obj2 != null)
            {
                str = obj2.ToString();
            }
            return str;
        }

        public string GetPreviousID(DataTable dataTable, string id)
        {
            string str = string.Empty;
            foreach (DataRowView view in dataTable.DefaultView)
            {
                if (view[BaseBusinessLogic.FieldID].ToString().Equals(id))
                {
                    return str;
                }
                str = view[BaseBusinessLogic.FieldID].ToString();
            }
            return str;
        }

        public void GetPreviousNextID(DataTable dataTable, string id)
        {
            this.PreviousID = this.GetPreviousID(dataTable, id);
            this.NextID = this.GetNextID(dataTable, id);
        }

        public DataTable GetPreviousNextID(bool deleteMark, string id, string order)
        {
            string sqlQuery = string.Concat(new object[] { " SELECT ID  FROM ", this.CurrentTableName, " WHERE (", BaseBusinessLogic.FieldCreateUserID, " = ", this.DbHelper.GetParameter(BaseBusinessLogic.FieldCreateUserID), " AND ", BaseBusinessLogic.FieldDeleteMark, " = ", deleteMark ? 1 : 0, ") ORDER BY ", order });
            string[] targetFileds = new string[1];
            object[] targetValues = new object[1];
            targetFileds[0] = BaseBusinessLogic.FieldCreateUserID;
            targetValues[0] = this.UserInfo.ID;
            DataTable dataTable = new DataTable(this.CurrentTableName);
            this.DbHelper.Fill(dataTable, sqlQuery, this.DbHelper.MakeParameters(targetFileds, targetValues));
            this.NextID = this.GetNextID(dataTable, id);
            this.PreviousID = this.GetPreviousID(dataTable, id);
            return dataTable;
        }

        public virtual string GetProperty(string id, string targetField)
        {
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id, targetField);
        }

        public virtual string GetProperty(IDbHelper dbHelper, string id, string targetField)
        {
            this.DbHelper = dbHelper;
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id, targetField);
        }

        public virtual string GetProperty(string[] names, object[] values, string targetField)
        {
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, names, values, targetField);
        }

        public virtual string GetProperty(string name, string value, string targetField)
        {
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, name, value, targetField);
        }

        public virtual string GetProperty(IDbHelper dbHelper, BaseUserInfo userInfo, string id, string targetField)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id, targetField);
        }

        public virtual string GetProperty(IDbHelper dbHelper, BaseUserInfo userInfo, string name, string value, string targetField)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, name, value, targetField);
        }

        public virtual string GetProperty(string name1, object value1, string name2, object value2, string targetField)
        {
            return DbLogic.GetProperty(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2, targetField);
        }

        public string GetStateMessage(StatusCode statusCode)
        {
            string str = string.Empty;
            switch (statusCode)
            {
                case StatusCode.Error:
                    return AppMessage.MSG0001;

                case StatusCode.OK:
                    return AppMessage.MSG9965;

                case StatusCode.OKAdd:
                    return AppMessage.MSG0009;

                case StatusCode.CanNotLock:
                    return AppMessage.MSG0043;

                case StatusCode.LockOK:
                    return AppMessage.MSG0044;

                case StatusCode.OKUpdate:
                    return AppMessage.MSG0010;

                case StatusCode.OKDelete:
                    return AppMessage.MSG0013;

                case StatusCode.ErrorCodeExist:
                    return AppMessage.Format(AppMessage.MSG0008, new string[] { AppMessage.MSG9977 });

                case StatusCode.ErrorFullNameExist:
                    return AppMessage.Format(AppMessage.MSG0008, new string[] { AppMessage.MSG9978 });

                case StatusCode.ErrorValueExist:
                    return AppMessage.Format(AppMessage.MSG0008, new string[] { AppMessage.MSG9800 });

                case StatusCode.ErrorUsernameExist:
                    return AppMessage.Format(AppMessage.MSG0008, new string[] { AppMessage.MSG9957 });

                case StatusCode.ErrorDataRelated:
                    return AppMessage.MSG0033;

                case StatusCode.ErrorDeleted:
                    return AppMessage.MSG0005;

                case StatusCode.ErrorChanged:
                    return AppMessage.MSG0006;

                case StatusCode.NotFound:
                    return AppMessage.MSG9956;

                case StatusCode.UserNotFound:
                    return AppMessage.MSG9966;

                case StatusCode.PasswordError:
                    return AppMessage.MSG9967;

                case StatusCode.LoginDeny:
                    return AppMessage.MSG9968;

                case StatusCode.ErrorOnLine:
                    return AppMessage.MSG0048;

                case StatusCode.ErrorMacAddress:
                    return AppMessage.MSG0049;

                case StatusCode.ErrorIPAddress:
                    return AppMessage.MSG0050;

                case StatusCode.ErrorOnLineLimit:
                    return AppMessage.MSG0051;

                case StatusCode.PasswordCanNotBeNull:
                    return AppMessage.Format(AppMessage.MSG0007, new string[] { AppMessage.MSG9961 });

                case StatusCode.SetPasswordOK:
                    return AppMessage.Format(AppMessage.MSG9963, new string[] { AppMessage.MSG9964 });

                case StatusCode.OldPasswordError:
                    return AppMessage.Format(AppMessage.MSG0040, new string[] { AppMessage.MSG9961 });

                case StatusCode.ChangePasswordOK:
                    return AppMessage.Format(AppMessage.MSG9962, new string[] { AppMessage.MSG9964 });
            }
            return str;
        }

        public string GetStateMessage(string statusCode)
        {
            if (string.IsNullOrEmpty(statusCode))
            {
                return string.Empty;
            }
            StatusCode code = (StatusCode)Enum.Parse(typeof(StatusCode), statusCode, true);
            return this.GetStateMessage(code);
        }

        public int ResetSortCode()
        {
            int num = 0;
            DataTable dT = this.GetDT(BaseBusinessLogic.FieldSortCode);
            string[] strArray = BaseSequenceDao.Instance.GetBatchSequence(this.DbHelper, this.CurrentTableName, dT.Rows.Count);
            int index = 0;
            foreach (DataRow row in dT.Rows)
            {
                num += this.SetProperty(row[BaseBusinessLogic.FieldID].ToString(), BaseBusinessLogic.FieldSortCode, strArray[index]);
                index++;
            }
            return num;
        }

        public void SetConnection(IDbHelper dbHelper)
        {
            this.DbHelper = dbHelper;
        }

        public void SetConnection(BaseUserInfo userInfo)
        {
            this.UserInfo = userInfo;
        }

        public void SetConnection(IDbHelper dbHelper, BaseUserInfo userInfo)
        {
            this.SetConnection(dbHelper);
            this.UserInfo = userInfo;
        }

        public virtual int SetDeleteMark(string id)
        {
            return this.SetProperty(BaseBusinessLogic.FieldID, id, BaseBusinessLogic.FieldDeleteMark, "1");
        }

        public virtual int SetDeleteMark(string[] ids)
        {
            return this.SetProperty(BaseBusinessLogic.FieldID, (object[])ids, BaseBusinessLogic.FieldDeleteMark, "1");
        }

        public virtual int SetDeleteMarkAll()
        {
            return this.SetProperty(BaseBusinessLogic.FieldCreateUserID, this.UserInfo.ID, BaseBusinessLogic.FieldDeleteMark, "1");
        }

        public virtual void SetParameter(IDbHelper dbHelper)
        {
            this.DbHelper = dbHelper;
        }

        public virtual void SetParameter(BaseUserInfo userInfo)
        {
            this.UserInfo = userInfo;
        }

        public virtual void SetParameter(IDbHelper dbHelper, BaseUserInfo userInfo)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
        }

        public virtual int SetProperty(string targetField, object targetValue)
        {
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, targetField, targetValue);
        }

        public virtual int SetProperty(IDbHelper dbHelper, string targetField, object targetValue)
        {
            this.DbHelper = dbHelper;
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, targetField, targetValue);
        }

        public virtual int SetProperty(string[] ids, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, (object[])ids, targetField, targetValue);
        }

        public virtual int SetProperty(string id, string[] targetFields, object[] targetValues)
        {
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id, targetFields, targetValues);
        }

        public virtual int SetProperty(string id, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id, targetField, targetValue);
        }

        public virtual int SetProperty(string[] names, object[] values, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, names, values, targetField, targetValue);
        }

        public virtual int SetProperty(IDbHelper dbHelper, BaseUserInfo userInfo, string targetField, object targetValue)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, targetField, targetValue);
        }

        public virtual int SetProperty(IDbHelper dbHelper, string id, string targetField, object targetValue)
        {
            this.DbHelper = dbHelper;
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id, targetField, targetValue);
        }

        public virtual int SetProperty(IDbHelper dbHelper, string id, string[] targetFields, object[] targetValues)
        {
            this.DbHelper = dbHelper;
            return this.SetProperty(id, targetFields, targetValues);
        }

        public virtual int SetProperty(string name, object value, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, name, value, targetField, targetValue);
        }

        public virtual int SetProperty(string name, object[] values, string targetField, object targetValue)
        {
            int num = 0;
            for (int i = 0; i < values.Length; i++)
            {
                num += DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, name, values[i], targetField, targetValue);
            }
            return num;
        }

        public virtual int SetProperty(IDbHelper dbHelper, BaseUserInfo userInfo, string id, string targetField, object targetValue)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, id, targetField, targetValue);
        }

        public virtual int SetProperty(IDbHelper dbHelper, BaseUserInfo userInfo, string[] ids, string targetField, object targetValue)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, BaseBusinessLogic.FieldID, (object[])ids, targetField, targetValue);
        }

        public virtual int SetProperty(IDbHelper dbHelper, string name, object value, string targetField, object targetValue)
        {
            this.DbHelper = dbHelper;
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, name, value, targetField, targetValue);
        }

        public virtual int SetProperty(IDbHelper dbHelper, BaseUserInfo userInfo, string name, object value, string targetField, object targetValue)
        {
            this.DbHelper = dbHelper;
            this.UserInfo = userInfo;
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, name, value, targetField, targetValue);
        }

        public virtual int SetProperty(string name1, object value1, string name2, object value2, string targetField, object targetValue)
        {
            return DbLogic.SetProperty(this.DbHelper, this.CurrentTableName, name1, value1, name2, value2, targetField, targetValue);
        }

        public virtual int Truncate()
        {
            return DbLogic.Truncate(this.DbHelper, this.CurrentTableName);
        }

        public virtual int Truncate(IDbHelper dbHelper)
        {
            this.DbHelper = dbHelper;
            return DbLogic.Truncate(this.DbHelper, this.CurrentTableName);
        }

        public virtual bool UpdateAfter()
        {
            return true;
        }

        public virtual bool UpdateBefore()
        {
            return true;
        }

        public virtual int UpdateEntity(object entity)
        {
            return 0;
        }

        public string ReturnStatusCode
        {
            get
            {
                return this.returnStatusCode;
            }
            set
            {
                this.returnStatusCode = value;
            }
        }

        public string ReturnStatusMessage
        {
            get
            {
                return this.returnStatusMessage;
            }
            set
            {
                this.returnStatusMessage = value;
            }
        }
    }
}